<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>td{width: 100px}</style>
</head>
<body>
<table border="1">
  <caption>个人信息</caption>
  <tr><td>照片:</td><td id="pic_td"></td></tr>
  <tr><td>姓名:</td><td id="name_td"></td></tr>
  <tr><td>年龄:</td><td id="age_td"></td></tr>
  <tr><td>好友:</td><td id="friends_td"></td></tr>
</table>
<input type="button" value="加载数据" onclick="f()">
<script>
    let picTd = document.querySelector("#pic_td");
    let nameTd = document.querySelector("#name_td");
    let ageTd = document.querySelector("#age_td");
    let friendsTd = document.querySelector("#friends_td");
    function f() {
        //模拟数据是从服务器请求到的
        let p1 = {name:"罗宾",age:20,imgUrl:"a.png",friends:["路飞","索隆","娜美"]};
        //把对象中的数据显示到页面中
        nameTd.innerText = p1.name;
        ageTd.innerText = p1.age;
        //显示图片
        let img = document.createElement("img");
        img.src = p1.imgUrl;
        img.width = 100;
        picTd.append(img);
        //显示好友
        let ul = document.createElement("ul");
        //遍历数组
        for (let friend of p1.friends) {
            let li = document.createElement("li");
            li.innerText = friend;
            ul.append(li);
        }
        friendsTd.append(ul);

    }
</script>
</body>
</html>










